//
//  PSTrick.h
//  PrefCore
//
//  Created by Sergey on 2/10/14.
//  Copyright (c) 2014 Play-on-smart. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "PSCard.h"
#import "PSPlayer.h"

/// Type for representing compressed tricks.
typedef uint32_t PSTrickHash;

/// Determines the number of player cards in a trick.
/// @param trick The input trick.
/// @return The number of player cards in this trick.
int PSTrickSize(PSTrickHash trick);

/// Adds a card from talon to the trick.
/// @param trick The input trick.
/// @param card The talon card to be added to the trick.
/// @return The modified trick representation.
PSTrickHash PSTrickAddCardTalon(PSTrickHash trick, PSCardIndex card);

/// Adds a card from a player to the trick.
/// @param trick The input trick.
/// @param player The player the card for whom is to be added.
/// @param card The player card to be added to the trick.
/// @return The modified trick representation.
PSTrickHash PSTrickAddCardPlayer(PSTrickHash trick, int player, PSCardIndex card);

/// Removes the last card from the trick.
/// @param trick The input trick.
/// @return The modified trick representation with the last card removed.
/// Note: Java version provides a function to remove a card for an arbitrary player.
/// Doing so puts the trick in an inconsistent state. However, Java program
/// always removes the last card, so it is never a problem.
PSTrickHash PSTrickRemoveLastCard(PSTrickHash trick);

/// Obtains the talon card from the trick's representation.
/// @param trick The input trick.
/// @return The talon card from this trick.
PSCard *PSTrickTalonCard(PSTrickHash trick);

/// Obtains a card from the player at the given index.
/// @param trick The input trick.
/// @param index The index of the player whose card is to be returned.
/// @return The card of the specified player.
PSCard *PSTrickCard(PSTrickHash trick, int index);

/// Determines whose card is at the specific index.
/// @param trick The input trick.
/// @param index The index of the card.
/// @return The index of the owner of the card at the specified index.
int PSTrickCardOwner(PSTrickHash trick, int index);

/// Obtains a card from the specified player.
/// @param trick The input trick.
/// @param player The player whose card is to be returned.
/// @return The card of the specified player.
PSCard *PSTrickCardOfPlayer(PSTrickHash trick, PSPlayer *player);

/// Gets the suit of the talon, or if it's not there, the suit of the first card.
/// @param trick The input trick.
/// @return The suit of this trick.
PSCardSuit PSTrickCardSuit(PSTrickHash trick);

/// Returns the highest card in this trick.
/// @param trick The input trick.
/// @param trump The trump suit of the game.
/// @return The highest card in this trick.
PSCard *PSTrickHighestCard(PSTrickHash trick, PSCardSuit trump);

/// Determines the index of the winner of this trick.
/// @param trick The input trick.
/// @param trump The trump suit of the game.
/// @return The index of the winner of this trick.
int PSTrickWinner(PSTrickHash trick, PSCardSuit trump);

/// Obtains a textual representation of the specified trick.
/// @param trick The input trick.
/// @param trump The trump suit of the game.
/// @return A textual representation of the specified trick.
NSString *PSTrickDescription(PSTrickHash trick, PSCardSuit trump);
